<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        class PriorityQueue {
            items = []

            assembleFun() {
                return { priority: this.priority, element: this.element }
            }

            enqueue(priority, element) {
                console.log(priority, element)
                
                if (this.items.length === 0) {
                    console.log(priority, element)
                    this.items.push({ priority: priority, element: element })
                    console.log(this.item)
                } else {
                    let added = false
                    for (let i = 0; i < this.items.length; i++) {
                        if (priority < this.items[i].priority) {
                            this.items.splice(i, 0, { priority: priority, element: element })
                        }
                        added = true
                        break
                    }

                    if (!added) {
                        this.items.push({ priority: priority, element: element })
                    }
                }

            }

            toString() {
                let str = ''
                for(let i=0; i<this.items.length; i++) {
                    str += this.items[i].priority + this.items[i].element + ' '
                }
                return str
            }
        }

        let pq = new PriorityQueue()
        pq.enqueue(200, 'aaa')
        pq.enqueue(100, 'bbb')
        console.log(pq.toString())
    </script>
</body>

</html>